package logic.p6_exception;

import org.junit.Test;

import java.io.File;
import java.io.FileInputStream;

/**
 * @ClassName: Java
 * @description:
 * @author: zxf
 * @create: 2021-06-11 16:55
 **/
public class ExceptionTest {

    @Test
    public void nullPointer(){
        String str = null;
        System.out.println(str.length());
    }

    public static void main(String[] args) {
//        if (args.length < 1){
//            System.out.println("请输入参数");
//            return;
//        }
//        try {
//            int a = Integer.parseInt(args[0]);
//            System.out.println(a);
//        }catch (RuntimeException e){
//            System.out.println(e.getCause());
//            throw new RuntimeException("参数错误");
//        }
        System.out.println(test());
    }


    public static int test (){
        int ret = 1;
        try {
            //int a = 5 / 0;
            return ret+1;
        }finally {
            return ret;
        }
    }

    public static void throwTest() throws Exception {

        FileInputStream inputStream = null;
        try {
            inputStream = new FileInputStream(new File(""));
        }catch (Exception e){
            // 抛出要声明，声明不一定抛出
            throw new Exception();
        }finally {

        }
    }
}

